package com.zsq.thread.test1;

/**
 * @author : zhang sq
 * @date : 2019/12/25 21:21
 **/
//线程状态
public class ThreadStatus {

    public static void main(String[] args) {
        Thread thread = new MyThread();
        System.out.println(thread.getState()); //状态 NEW
        System.out.println(thread.getName()); //名称
        System.out.println(thread.getId());  //id
        System.out.println(thread.getPriority());//优先级
        thread.start();
        System.out.println(thread.getState());//状态 RUNNABLE
        try {
            thread.join();
        }catch (Exception e){
            e.printStackTrace();
        }
        System.out.println(thread.getState());//状态 TERMINATED
    }

    //继承
    static class MyThread extends Thread {
        @Override
        public void run() {
            System.out.println(this.getState());//状态
            for (int i = 0; i <10; i++) {
                try {
                    Thread.sleep(300);
                }catch (Exception e){
                    e.printStackTrace();
                }
                System.out.println(i);
            }
        }
    }
}
